<!---

Copyright 2008:

Author: Marco van den Oever
Company: WSO
Website: http://www.webserviceonline.biz
Email: marco@webserviceonline.biz

License: 

This software is licensed under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
For a copy of the GNU General Public License check the license folder or see <http://www.gnu.org/licenses/>.

Description:

wsoFarcryBanners, a Farcry plugin to show and rotate banners from one or more banner clients on a Farcry based project

Build with great support from the Farcry-Dev group! (Google on Farcry-Dev)

Created: 14/09/08

Tested on CF8

--->
<cfsetting enablecfoutputonly="true" />
<cfimport taglib="/farcry/core/tags/formtools" prefix="ft" />
<cfimport taglib="/farcry/core/tags/admin/" prefix="admin">
<!--- set up page header --->
<admin:header title="Banner Statistics" />
<!--- check if the polling rule is deployed, else show link to deploy --->

<cftry>
  <cfset oFormtoolUtil = createObject("component",
"farcry.core.packages.farcry.formtools") />
  <cfset sqlColumns="objectid" />
  <cfset bannerrule = oFormtoolUtil.getRecordset(sqlColumns=sqlColumns,
sqlWhere="objectid = objectid", typename="ruleBanners",
bCheckVersions=true) />
  <cfcatch type="database">
    <cfoutput>The 'Banner' rule has not been deployed yet. Click <a href="/webtop/admin/coapiRules.cfm?deploy=ruleBanners">here</a> to deploy it now. </cfoutput>
    <cfabort>
  </cfcatch>
</cftry>
<!--- check if the banners type is deployed, else show link to deploy --->
<cftry>
  <cfset oFormtoolUtil = createObject("component",
"farcry.core.packages.farcry.formtools") />
  <cfset sqlColumns="objectid" />
  <cfset banners = oFormtoolUtil.getRecordset(sqlColumns=sqlColumns,
sqlWhere="objectid = objectid", typename="banners",
bCheckVersions=true) />
  <cfcatch type="database">
    <cfoutput>The 'Banners' content type has not been deployed yet. Click <a href="/webtop/admin/customadmin.cfm?module=customlists/banners.cfm&plugin=wsoFarcryBanners&deploy=true">here</a> to deploy it now.</cfoutput>
    <cfabort>
  </cfcatch>
</cftry>
<!--- check if any banner data exists, else show link to create banner --->
<cfif banners.q.recordcount LE 0>
  <cfoutput>Currently there is no banner to get data from. Click <a href="/webtop/admin/customadmin.cfm?module=customlists/banners.cfm&plugin=wsoFarcryBanners">here</a> to create one now.</cfoutput>
  <cfabort>
</cfif>
<!--- get all the banner clients --->
<cfset oFormtoolUtil = createObject("component",
"farcry.core.packages.farcry.formtools") />
<cfset sqlColumns="ObjectID,contactname" />
<cfset RecordsPerPage="1000" />
<cfset bannerclients = oFormtoolUtil.getRecordset(sqlColumns=sqlColumns,
sqlWhere="ObjectID = ObjectID", typename="bannerclients",
bCheckVersions=true) />
<cfif ISDEFINED("FORM.bannerclients")>
  <cfset application.bannerclients = FORM.bannerclients>
  <cfelse>
  <cfset application.bannerclients = bannerclients.q.ObjectID>
</cfif>
<cfset oFormtoolUtil = createObject("component",
"farcry.core.packages.farcry.formtools") />
<cfset sqlColumns="ObjectID,bannername,hitsmade,hitsleft,viewsmade,viewsleft" />
<cfset RecordsPerPage="1000" />
<cfset clientbanners = oFormtoolUtil.getRecordset(sqlColumns=sqlColumns,
sqlWhere="(abannerclients) IN (SELECT ObjectID FROM #application.dbowner#bannerclients WHERE #application.dbowner#bannerclients.ObjectID = '#application.bannerclients#')", typename="banners", bCheckVersions=true) />
<!--- get client banner info --->
<cfset oFormtoolUtil = createObject("component",
"farcry.core.packages.farcry.formtools") />
<cfset sqlColumns="ObjectID,bannername,datetimecreated,datetimelastupdated,hitsmade,hitsleft,viewsmade,viewsleft" />
<cfset RecordsPerPage="1000" />
<cfset clientbanner = oFormtoolUtil.getRecordset(sqlColumns=sqlColumns,
sqlWhere="ObjectID = '#clientbanners.q.ObjectID#'", typename="banners", bCheckVersions=true) />
<cfoutput>
  <h1>Banner Statistics</h1>
  <cfif #clientbanners.q.recordcount# GT 0>
    <table>
      <ft:form>
        <tr>
          <td colspan="2" align="left">&nbsp;</td>
        </tr>
        <tr>
          <td><select name = "bannerclients">
              <cfloop query="bannerclients.q">
                <option value="#bannerclients.q.ObjectID#"<cfif #bannerclients.q.ObjectID# EQ #application.bannerclients#> selected="selected"</cfif>>#bannerclients.q.contactname#</option>
              </cfloop>
            </select></td>
          <td align="left"><ft:button value="Select" size="small" />
            <ft:button value="xls" size="small" />
          </td>
        </tr>
      </ft:form>
      <cfloop query="clientbanners.q">
        <ft:form>
          <tr>
            <td align="left">#clientbanners.q.bannername#</td>
            <td align="left">
			
			<!--- <ft:button value="Edit" size="small" onclick="window.location='/webtop/conjuror/invocation.cfm?objectid=#objectid#&amp;typename=banners&amp;method=edit&amp;ref=typeadmin&amp;module=customlists/banners.cfm&amp;plugin=wsoFarcryBanners';" /> --->
			
				<button type="button" name="Edit" value="Edit" onclick="window.location='/webtop/conjuror/invocation.cfm?objectid=#objectid#&amp;typename=banners&amp;method=edit&amp;ref=typeadmin&amp;module=customlists/banners.cfm&amp;plugin=wsoFarcryBanners'">Edit</button>
		
            </td>
          </tr>
          <tr>
            <td colspan="2" align="left"><!--- show the banner statistics in cfchart --->
              <cfchart format="png"
chartwidth="300" chartheight="300" showlegend="yes" show3d="yes">
              <cfchartseries type="pie">
              <cfchartdata item="hits made" value="#clientbanners.q.hitsmade#">
              <cfchartdata item="hits left" value="#clientbanners.q.hitsleft#">
              <cfchartdata item="views made" value="#clientbanners.q.viewsmade#">
              <cfchartdata item="views left" value="#clientbanners.q.viewsleft#">
              </cfchartseries>
              </cfchart>
            </td>
          </tr>
        </ft:form>
      </cfloop>
    </table>
    <cfelse>
    Currently this banner client has no assigned banners. Click <a href="/webtop/admin/customadmin.cfm?module=customlists/banners.cfm&plugin=wsoFarcryBanners">here</a> to create one now.
  </cfif>
  <!--- if the form was submitted by the Excel button, save data to Excel --->
  <ft:processform action="xls">
    <!--- Import the POI tag library. --->
    <cfimport taglib="/farcry/plugins/wsoFarcryBanners/packages/custom/poi/" prefix="poi" />
    <!--- 
	Create an excel document and store binary data into 
	REQUEST variable. 
--->
    <poi:document 
	name="REQUEST.ExcelData"
	file="#ExpandPath( './bannerclient_statistics.xls' )#"
	style="font-family: verdana ; font-size: 10pt ; color: black ; white-space: nowrap ;">
      <!--- Define style classes. --->
      <poi:classes>
        <poi:class
			name="title"
			style="font-family: verdana ; font-size: 12pt ; color: black ; text-align: center ;"
			/>
        <poi:class 
			name="header" 
			style="font-family: verdana ; font-size: 10pt ; color: black ; background-color: GREY_25_PERCENT ; border-bottom: solid 3px GREY_40_PERCENT ;" 
			/>
      </poi:classes>
      <!--- Define Sheets. --->
      <poi:sheets>
        <poi:sheet 
			name="bannerclient_statistics"
			freezerow="2"
			orientation="landscape"
			zoom="100%">
          <!--- Define global column styles. --->
          <poi:columns>
            <poi:column style="width: 150px ; text-align: center ;" />
            <poi:column style="width: 150px ; text-align: center ;" />
            <poi:column style="width: 150px ; text-align: center ;" />
            <poi:column style="width: 150px ; text-align: center ;" />
            <poi:column style="width: 150px ; text-align: center ;" />
            <poi:column style="width: 150px ; text-align: center ;" />
            <poi:column style="width: 150px ; text-align: center ;" />
          </poi:columns>
          <!--- Title row. --->
          <poi:row class="title">
            <poi:cell value="bannerclient_statistics" colspan="7" />
          </poi:row>
          <!--- Header row. --->
          <poi:row class="header">
            <poi:cell value="Date / Time created" />
            <poi:cell value="Bannerclient" />
            <poi:cell value="Bannername" />
            <poi:cell value="Hits made" />
            <poi:cell value="Hits left" />
            <poi:cell value="Views made" />
            <poi:cell value="Views left" />
          </poi:row>
          <cfloop query="clientbanners.q">
            <!--- Output the polling data --->
            <poi:row>
              <poi:cell type="date" value="#clientbanner.q.datetimecreated#" />
              <poi:cell value="#bannerclients.q.contactname#" />
              <poi:cell value="#clientbanners.q.bannername#" />
              <poi:cell type="numeric" value="#clientbanners.q.hitsmade#" />
              <poi:cell type="numeric" value="#clientbanners.q.hitsleft#" />
              <poi:cell type="numeric" value="#clientbanners.q.viewsmade#" />
              <poi:cell type="numeric" value="#clientbanners.q.viewsleft#" />
            </poi:row>
          </cfloop>
        </poi:sheet>
      </poi:sheets>
    </poi:document>
    <!--- Tell the browser to expect an Excel file attachment. --->
    <cfheader
	name="content-disposition"
	value="attachment; filename=polling_statistics.xls"
	/>
    <!--- 
	Tell browser the length of the byte array output stream. 
	This will help the browser provide download duration to 
	the user. 
--->
    <cfheader
	name="content-length"
	value="#REQUEST.ExcelData.Size()#"
	/>
    <!--- Stream the binary data to the user. --->
    <cfcontent
	type="application/excel"
	variable="#REQUEST.ExcelData.ToByteArray()#"
	/>
  </ft:processform>
</cfoutput>
<!--- setup footer --->
<admin:footer>
<cfsetting enablecfoutputonly="false" />
